package com.schrodinger.zbdp.licensegen.frame.util;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JComponent;
import javax.swing.JFileChooser;

import com.schrodinger.zbdp.licensegen.util.DesManager;

public class LicensGenUtil {
	public static void licensGenByFile(String csbPath, String licensPath) {
		DesManager des = new DesManager();
		try {
			des.genDesFile(csbPath, licensPath);
		} catch (Exception ex) {
			Logger.getLogger(LicensGenUtil.class.getName()).log(Level.SEVERE,
					null, ex);
		}
	}

	public static String getLicensGenCsbPath(JComponent jc) {
		String[] xml = { "log" };
		JFileChooser c = new JFileChooser();
		GenericFile filter = new GenericFile(xml, "log");
		c.addChoosableFileFilter(filter);
		int rVal = 0;
		rVal = c.showOpenDialog(jc);
		if (rVal == 0)
			return c.getSelectedFile().getPath();

		return "";
	}

	public static String setLicensGenlicensPath(JComponent jc) {
		String[] xml = { "des" };
		JFileChooser c = null;
		GenericFile filter = new GenericFile(xml, "des");
		int rVal = -1;
		c = new JFileChooser();
		c.addChoosableFileFilter(filter);
		rVal = c.showSaveDialog(jc);
		if (rVal == 0) {
			String path = c.getSelectedFile().getPath();
			if (path.indexOf("des") == -1) {
				path = path + ".des";
				return path;
			}
			return path;
		}

		return "";
	}
}